package com.codi.api.controller.portfolio;

import com.codi.base.log.annotation.Loggable;
import com.codi.bus.core.resultModel.BaseResult;
import com.codi.bus.core.service.FundCombinationHistoryService;
import com.codi.bus.core.service.FundCombinationService;
import com.codi.bus.core.service.FundWarehouseTransferService;
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("portfolio/detail")
public class PortfolioQueryController {
    @Autowired
    private FundCombinationService fundCombinationService;

//    @Autowired
//    private HsPortfolioQryService hsPortfolioQryService;

    @Autowired
    private FundCombinationHistoryService fundCombinationHistoryService;

    @Autowired
    private FundWarehouseTransferService fundWarehouseTransferService;

    /**
     * 查询所有基金组合列表
     *
     * @return
     * @throws Exception
     */
    @Loggable
    @GetMapping("/query")
    public BaseResult query() throws Exception {
        BaseResult result = new BaseResult();
        result.setResult(fundCombinationService.queryPortfolios());
        return result;
    }

    /**
     * 查询首页三只基金组合列表
     *
     * @return
     */
    @Loggable
    @GetMapping("/query_three")
    public BaseResult queryThree() {
        BaseResult result = new BaseResult();

        result.setResult(fundCombinationService.queryThreeCombinations());

        return result;
    }

    @Loggable
    @PostMapping("/query_combination_info")
    public BaseResult queryCombination(String combinationCode) {
        BaseResult result = new BaseResult();

        if (!Strings.isNullOrEmpty(combinationCode)) {
            result.setResult(fundCombinationService.queryByCombinationCode(combinationCode));
        }

        return result;
    }

    @Loggable
    @PostMapping("/query_chart")
    public BaseResult queryChart(String combinationCode, String type) {
        BaseResult result = new BaseResult();

        if (!Strings.isNullOrEmpty(combinationCode) && !Strings.isNullOrEmpty(type)) {
            result.setResult(fundCombinationHistoryService.queryByDate(type, combinationCode));
        }

        return result;
    }

    @Loggable
    @GetMapping("query_recent_transfer")
    public BaseResult queryRecentTransfer(String combinationCode) {
        BaseResult result = new BaseResult();

        if (!Strings.isNullOrEmpty(combinationCode)) {
            result.setResult(fundWarehouseTransferService.queryRencentTransfer(combinationCode));
        }

        return result;
    }

    @Loggable
    @GetMapping("query_transfers")
    public BaseResult queryTransfers(String combinationCode) {
        BaseResult result = new BaseResult();

        if (!Strings.isNullOrEmpty(combinationCode)) {
            result.setResult(fundWarehouseTransferService.queryTransfers(combinationCode));
        }

        return result;
    }
}
